package cn.openea.perpartner.meily.constant.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author ysk
 * @version 1.0.1
 * @Description 快递状态
 * @createTime 2023年05月10日 11:31:00
 */
@Getter
public enum ExpressStatus {
    NO_LOGISTICS((short) 99, "暂无物流"),
    COLLECTION((short) 0, "揽收"),
    INTRANSIT((short) 1, "在途"),
    DIFFICULT((short) 2, "疑难"),
    SIGN((short) 3, "签收"),
    WITHDRAWAL((short) 4, "退签"),
    DISPATCH((short) 5, "派件"),
    RETURN((short) 6, "退回"),
    TRANSFER((short) 7, "转投"),
    CUSTOMS_CLEARANCE((short) 8, "清关"),
    REFUSAL((short) 14, "拒签"),
    ;

    /**
     * 快递状态
     */
    private Short status;

    /**
     * 名称 注意，这里需要与快递100接口返回的值一致
     */
    private String statusName;

    ExpressStatus(Short status, String statusName) {
        this.status = status;
        this.statusName = statusName;
    }

    public static ExpressStatus getInstance(short status) {
        for (ExpressStatus value : values()) {
            if (status == value.getStatus()) {
                return value;
            }
        }
        return null;
    }

    public static ExpressStatus getInstance(String statusName) {
        if (StringUtils.isBlank(statusName)) {
            return null;
        }
        for (ExpressStatus value : values()) {
            if (statusName.equals(value.getStatusName())) {
                return value;
            }
        }
        return null;
    }

    /**
     * 是否为签收状态
     */
    public static boolean isSing(short status) {
        return SIGN.status.equals(status);
    }

    /**
     * 是否在运输中
     */
    public static boolean isInTransport(short status) {
        // 不为揽收和暂无物流的都为运输中
        return !COLLECTION.status.equals(status) && !NO_LOGISTICS.status.equals(status);
    }
}
